<template>
  <div class="container">
    <div class="header">
      <el-form ref="form" :model="form">
        <el-row type="flex" justify="space-between" :gutter="20">
          <el-col :span="20">
            <el-row type="flex" justify="start" :gutter="20">
              <el-col :span="5">
                <el-form-item prop="shopType">
                  <el-select v-model="form.shopType" class="select">
                    <template #prefix>
                      <div class="select-prefix">商店类型：</div>
                    </template>
                    <el-option
                      v-for="item in shopTypeList"
                      :key="item.value"
                      :label="item.dictLabel"
                      :value="item.dictValue">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item prop="shopName">
                  <el-input
                    class="search"
                    placeholder="搜索商店名称"
                    prefix-icon="el-icon-search"
                    v-model="form.shopName"
                  >
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="4">
            <div class="btn-group">
              <el-button class="query" @click="getCulturalAndCreativeList">查询</el-button>
              <el-button plain class="clear" @click="resetForm">清空</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="content">
      <div class="table-header">
        <span class="left">列表</span>
        <div class="right">
          <el-button type="primary" icon="el-icon-plus" class="add" @click="toAdd">新增</el-button>
          <el-button type="primary" icon="el-icon-download" class="export" @click="exportHandle">导出</el-button>
          <el-button icon="el-icon-refresh-right" class="refresh" @click="getCulturalAndCreativeList">刷新</el-button>
        </div>
      </div>
      <div class="table-box">
        <el-table
          :data="shopList"
          :header-cell-style="headerCellStyle"
          style="width: 100%">
          <el-table-column
            type="index"
            label="序号"
            width="80"
            align="center">
          </el-table-column>
          <el-table-column
            prop="jingquName"
            label="所属景区"
            min-width="200">
          </el-table-column>
          <el-table-column
            prop="name"
            label="店铺名称"
            min-width="200">
          </el-table-column>
          <el-table-column
            prop="type"
            label="店铺类型"
            min-width="150">
            <template slot-scope="scope">
              {{getShopTypeName(scope.row.type)}}
            </template>
          </el-table-column>
          <el-table-column
            prop="merchandiseNum"
            label="商品种类"
            min-width="150">
          </el-table-column>
          <el-table-column
            prop="address"
            label="地址"
            min-width="200">
          </el-table-column>
          <el-table-column
            prop="status"
            label="商铺状态"
            min-width="130">
            <template slot-scope="scope">
              <span v-if="scope.row.status === '0'" class="status-normal">正常营业</span>
              <span v-if="scope.row.status === '1'" class="status-stop">暂停营业</span>
              <span v-if="scope.row.status === '2'" class="status-clear">店铺撤场</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            min-width="180"
            align="center"
            fixed="right">
            <template slot-scope="scope">
              <el-link type="primary" class="look" @click="look(scope.row.id)">查看</el-link>
              <el-link type="success" class="edit" @click="edit(scope.row.id)">编辑</el-link>
              <el-link type="warning" class="delete" @click="remove(scope.row.id)">删除</el-link>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination">
          <span>总共 {{pageTotal}} 条</span>
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            @prev-click="handlePrevClick"
            @next-click="handleNextClick"
            :current-page.sync="currentPage"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize"
            layout="prev, pager, next, sizes"
            :total="pageTotal">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import {getDicts} from "@/api/system/dict/data";
import {getCulturalAndCreativeList} from "@/api/form/cultrue";
import {exportHandle} from "@/api/form/cultrue";
import {downloadFile} from "@/utils";

export default {
  async mounted() {
    await this.getQiyeType()
    await this.getCulturalAndCreativeList()
  },
  data () {
    return {
      form: {
        shopType: '',
        shopName: '',
      },
      shopTypeList: [],
      shopList: [],
      currentPage: 1,
      pageSize: 10,
      pageTotal: 0
    }
  },
  computed: {
    headerCellStyle () {
      return {'font-size': '16px','font-weight': 400,color: '#999999',background: '#fff'}
    }
  },
  methods: {
    remove(shopId) {
      this.$router.push(`/form/culture/add?type=look&shopId=${shopId}`)
    },
    look(shopId) {
      this.$router.push(`/form/culture/detail?type=look&shopId=${shopId}`)
    },
    edit(shopId) {
      this.$router.push(`/form/culture/edit?type=edit&shopId=${shopId}`)
    },
    async getQiyeType() {
      const { code, data } = await getDicts('merchant_type')
      if (code === 200) {
        this.shopTypeList = data
      }
    },
    async exportHandle() {
      const { code, data, msg } = await exportHandle({
        name: this.form.shopName,
        pageNum: this.currentPage,
        pageSize: this.pageSize
      })
      if (code !== 200) {
        this.$message({ message: msg, type: 'error' })
        return
      }
      downloadFile(data, '文创列表')
      this.$message({ message: '已导出', type: 'success' })
    },
    async getCulturalAndCreativeList() {
      const { code, data, msg } = await getCulturalAndCreativeList({
        type: this.form.shopType,
        name: this.form.shopName,
        pageNum: this.currentPage,
        pageSize: this.pageSize
      })
      if (code === 200) {
        this.shopList = data.rows
        this.pageTotal = data.total
      } else {
        this.$message({message: msg, type: 'error'})
      }
    },
    getShopTypeName(type) {
      const dict = this.shopTypeList.find(item => item.dictValue === type)
      if (!dict) return '-'
      return dict.dictLabel
    },
    resetForm() {
      this.$refs.form.resetFields()
    },
    handleSizeChange (pageSize) {
      this.pageSize = pageSize
      this.getCulturalAndCreativeList()
    },
    handleCurrentChange (currentPage) {
      this.currentPage = currentPage
      this.getCulturalAndCreativeList()
    },
    handlePrevClick (currentPage) {
      this.currentPage = currentPage
      this.getCulturalAndCreativeList()
    },
    handleNextClick (currentPage) {
      this.currentPage = currentPage
      this.getCulturalAndCreativeList()
    },
    toAdd () {
      this.$router.push(`/form/culture/add?type=add`)
    },
  }
}
</script>
<style scoped lang="scss">
.container {
  height: 100%;
  width: 100%;
  background-color: var(--theme_bg_color);
  display: flex;
  flex-direction: column;
  .header {
    width: 100%;
    background: #FFFFFF;
    border-radius: 8px;
    padding: 15px 15px 15px 25px;
    margin-bottom: 16px;

    ::v-deep .el-form-item {
      margin-bottom: 0 !important;
    }
    .select {
      height: 32px;
      width: 100%;
      ::v-deep .el-input--prefix .el-input__inner {
        padding-left: 81px;
      }
    }
    .select-prefix {
      font-size: 14px;
      font-weight: 400;
      color: #8F959E;
      line-height: 36px;
    }
    .btn-group {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      .query {
        width: 72px;
        height: 32px;
        background: #3370FF;
        border: none;
        color: #ffffff;
      }
      .clear {
        width: 72px;
        height: 32px;
      }
    }
  }
  .content {
    flex: 1;
    width: 100%;
    background: var(--theme_bg_color);
    position: relative;
    .table-header {
      padding: 10px 15px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-bottom: 1px solid #E4E7ED;
      background-color: #fff;
      .left {
        font-size: 16px;
        font-weight: 400;
        color: #111111;
      }
      .right {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        .add {
          background: #3370FF;
          border: none;
        }
        .export {
          background: #79CF1C;
          border: none;
        }
      }
    }
    .table-box {
      width: 100%;
      position: absolute;
    }
    .status-normal {
      color: #2E69F8;
    }
    .status-stop {
      color: #FF8521;
    }
    .status-clear {
      color: #999999;
    }
    .pagination {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      padding: 10px 0;
      background: #fff;
      span {
        font-size: 5rpx;
      }
    }
    .edit {
      margin: 0 20px;
    }
    .tag {
      width: 60px;
      height: 24px;
      border-radius: 2px 2px 2px 2px;
      font-size: 14px;
      font-weight: 400;
      display: flex;
      align-items: center;
      justify-content: center;
      i {
        margin-right: 5px;
      }
    }
    .business {
      background: #D6E2FF;
      color: #245BDB;
    }
  }
}
</style>
